package math.vectorSpace.R3.object;

import java.awt.Color;

import java.awt.Graphics2D;
import math.vectorSpace.R3.Point3D;
import math.vectorSpace.R3.Segment3D;
import math.vectorSpace.R3.visualization.Render3D;
import math.vectorSpace.R3.visualization.RenderOrthographic;
import math.vectorSpace.R3.visualization.VisualizationProperties;

public abstract class MovableObject extends Object3D {

    protected Point3D start, end;

    protected double speedX, speedY, speedZ;

    public void setBoundary(Point3D start, Point3D end) {
        this.start = start;
        this.end = end;
    }

    public void setBoundary(double x1, double y1, double z1, double x2,
            double y2, double z2) {
        setBoundary(new Point3D(x1, y1, z1), new Point3D(x2, y2, z2));
    }

    public void setSpeed(double x, double y, double z) {
        this.speedX = x;
        this.speedY = y;
        this.speedZ = z;
    }

    public void move() {
        if ((center.getX() > end.getX()) || (center.getX() < start.getX())) {
            speedX = -speedX;
        }
        if ((center.getY() > end.getY()) || (center.getY() < start.getY())) {
            speedY = -speedY;
        }
        if ((center.getZ() > end.getZ()) || (center.getZ() < start.getZ())) {
            speedZ = -speedZ;
        }
        center = center.add(speedX, speedY, speedZ);
    }

    public void drawTracker(Render3D render, Graphics2D graphics) {
        Segment3D trackerX, trackerY, trackerZ;

        trackerX = new Segment3D(start.getX(), center.getY(), center.getZ(),
                end.getX(), center.getY(), center.getZ());
        trackerY = new Segment3D(center.getX(), start.getY(), center.getZ(),
                center.getX(), end.getY(), center.getZ());
        trackerZ = new Segment3D(center.getX(), center.getY(), start.getZ(),
                center.getX(), center.getY(), end.getZ());

        trackerX.draw(render, graphics, new VisualizationProperties(Color.RED));
        trackerY.draw(render, graphics, new VisualizationProperties(Color.GREEN));
        trackerZ.draw(render, graphics, new VisualizationProperties(Color.BLUE));
    }
}
